package top.drinyeit.nongmao.presenter;

import android.support.v4.app.Fragment;

import java.util.ArrayList;
import java.util.List;

import top.drinyeit.nongmao.interfaces.IResult;
import top.drinyeit.nongmao.adapter.CVAdapter;
import top.drinyeit.nongmao.adapter.HomeIconAdapter;
import top.drinyeit.nongmao.adapter.HomeMoreAdapter;
import top.drinyeit.nongmao.model.AppHomeBean;
import top.drinyeit.nongmao.retrofit.HttpResponse;
import top.drinyeit.nongmao.retrofit.RetrofitMethod;
import top.drinyeit.nongmao.retrofit.subscriber.CommonSubscriber;
import top.drinyeit.nongmao.retrofit.subscriber.SubscriberListener;

import static top.drinyeit.nongmao.app.Constant.COMMON_SUCCESS;

/**
 * Created by wu on 2018/1/8.
 */

public class ShopPresenter {
    private Fragment fragment;
    private List<AppHomeBean.BannerBean> banner;
    private CVAdapter cvAdapter;
    private HomeMoreAdapter homeMoreAdapter;
    private HomeIconAdapter homeIconAdapter;
    private IResult iResult;

    public ShopPresenter(Fragment fragment, IResult iResult) {
        this.fragment = fragment;
        this.iResult = iResult;
    }

    //获取首页信息
    public void getApp() {
        banner = new ArrayList<>();
        CommonSubscriber<HttpResponse<AppHomeBean>> subscriber = new CommonSubscriber<>(new SubscriberListener<HttpResponse<AppHomeBean>>() {
            @Override
            public void onError(String e, int code) {
                iResult.error(e,code);
            }

            @Override
            public void onNext(final HttpResponse<AppHomeBean> o) {
                if (o.getCode() != COMMON_SUCCESS) {
                    iResult.error(o.getMessage(),-1);
                } else {
                    iResult.success("success",o);
                }
            }
        });
        RetrofitMethod.getInstance().getApp(subscriber);
    }
}
